﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Timers;
using DLL.Entities;


namespace COM
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        ReadXML xRead = new ReadXML();

        private void Form1_Load(object sender, EventArgs e)
        {
            
            COM_Config modver = new COM_Config();
            modver = xRead.ReadCOMConfig();
                   
            txtComModel.Text = Convert.ToString(modver.Model);
            txtComVersion.Text = Convert.ToString(modver.Version);
        }

        string cwd = System.IO.Directory.GetCurrentDirectory();

        private void tRead_Tick(object sender, EventArgs e)
        {
            if (File.Exists("../../../DLL/XML/RAD_Update.xml"))
            {
                Targets bogie = new Targets();
                bogie = xRead.ReadRADEvent("../../../DLL/XML/RAD_Update.xml");
                       
                txtAltitude.Text = bogie.Altitude;
                txtSpeed.Text = bogie.Speed;
                txtDistance.Text = bogie.Distance;
                txtDirection.Text = bogie.Direction;
                txtSize.Text = bogie.Size;
                txtBogie.Text = bogie.TargetName;

                File.Delete("../../../DLL/XML/RAD_Update.xml");

                txtRadarStatus.Text = "Online";
            }
            else
            {
                txtRadarStatus.Text = "Offline";
                txtBogie.Text = "N/A";
                txtAltitude.Text = "N/A";
                txtSpeed.Text = "N/A";
                txtDistance.Text = "N/A";
                txtDirection.Text = "N/A";
                txtSize.Text = "N/A";
            }


            if (File.Exists("../../../DLL/XML/Mis_Status.xml"))
            {

                MISStatus currentMis = new MISStatus();
                currentMis = xRead.ReadMISStatus("../../../DLL/XML/Mis_Status.xml");


                txtMisRem.Text = Convert.ToString(currentMis.MissileCount);
                txtMissileType.Text = currentMis.MissileType;
                txtMissileStatus.Text = currentMis.CurrentStatus;

                File.Delete("../../../DLL/XML/Mis_Status.xml");
            }
            else
            {
                txtMisRem.Text = "0";
                txtMissileType.Text = "N/A";
                txtMissileStatus.Text = "Offline";
            }
                            
        }      
    }
}